<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>编辑模块（权限）添加</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        
        var moduleId = new Ext.form.Hidden({
          name: 'id',
          value:'<%=params[:id]%>'
        });

        var parentId = new Ext.form.Hidden({
          name: 'parent_id'
        });


        var name = new Ext.form.TextField({
          fieldLabel: '模块名称',
          name: 'name',
          anchor: '90%'
        });

        var desc = new Ext.form.TextArea({
          fieldLabel: '模块描述',
          name: 'description',
          allowBlank: false,
          height: 80,
          anchor: '90%'
        });
        
        //提交按钮
        var submitButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            submitButton.setDisabled(true);
            if (editPrivilegeFormPanel.form.isValid()) {
              editPrivilegeFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    editPrivilegeModuleWin.destroy();
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  submitButton.enable();
                },
                failure: function(result, request){
                  submitButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              submitButton.enable();
              
            }
          }
        })
        
        var editPrivilegeFormPanel = new Ext.form.FormPanel({
          labelWidth: 75,
          width: '345',
          labelAlign: 'right',
          frame : true,
          url: '/privilege/updateSysPrivilege',
          method: 'GET',
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            }, {
              name: 'number'
            }, {
              name: 'name'
            }, {
              name: 'description'
            }, {
              name: 'parent_id'
            }]),
          items: [moduleId,parentId,name,desc],
          buttons: [submitButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                editPrivilegeModuleWin.destroy();
              }
            }]
        });
        editPrivilegeFormPanel.form.load({
          url: '/privilege/getSysPrivilegeById?id=' + moduleId.getValue(),
          method : 'GET',
          waitMsg: '正在载入数据...',
          success: function(form, action){
          },
          failure: function(form, action){
            Ext.MessageBox.alert('提示信息', '信息加载失败');
          }
        });
        editPrivilegeFormPanel.render('sys_privilege_module_form');
      })
    </script>
    <div id="sys_privilege_module_form"></div>
  </body>
</html>
